package com.poorstu.manager.impl;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.common.base.model.PaginationSupport;
import com.common.base.model.PublicFinalData;
import com.poorstu.dao.LeaseDao;
import com.poorstu.dao.LoginDao;
import com.poorstu.manager.LeaseManager;
import com.poorstu.model.LeaseMod;
import com.poorstu.model.LoadMoneyMod;
import com.poorstu.model.LoginMod;

public class LeaseManagerImpl implements LeaseManager{
	   private LeaseDao leaseDao;
	   private LoginDao loginDao;
	public int leaseAdd(LeaseMod leaseMod,int allUserId) {
		
		LoginMod loginMod=loginDao.selectUserById(allUserId);
		leaseMod.setLogin(loginMod);
	    int a=0;
		try{
			leaseDao.leaseAdd(leaseMod);
			a=1;
			}catch(Exception e){
		
			}
		return a;
	}


	public List<LeaseMod> leaseMag() {
		
		List<LeaseMod> leaseList=leaseDao.leaseMag();
		if(leaseList.size()<=0){
		return null;
		}
		return leaseList;
	}


public int leaseDelete(int[] leaseid) {
			
	
	List<LeaseMod> leaseList = new ArrayList<LeaseMod>();
	for (int i = 0; i<leaseid.length; i++) {
		LeaseMod lease = leaseDao.selLeaseById(leaseid[i]);
		leaseList.add(lease);
	}
	return leaseDao.leaseDelete(leaseList);
}
	
	
//			int d=leaseDao.leaseDelete(leaseid);
//			if(d==1)
//			{
//			return 1;
//			}
//			else return 0;
	//	}
	
public LeaseMod getLeaseById(int leaseId) {
		
		LeaseMod leaseMod=leaseDao.selLeaseById(leaseId);
		return leaseMod;
		
	}


	public int leaseChange(LeaseMod lease) {
		
		int a=0;
		try{
		LeaseMod leaseMod=leaseDao.selLeaseById(lease.getLeaseId());
		
		leaseMod.setLeaseName(lease.getLeaseName());
		leaseMod.setLeaContent(lease.getLeaContent());
		leaseMod.setLeaTime(new Date());
			
	    leaseDao.changeLease(leaseMod);
		   a=1;
		}catch(Exception e){
			e.getMessage();
		}
		return a;
	}


	
	
	public List<LoadMoneyMod> getLoadMoney() {
		
		return leaseDao.getLoadMoney();
	}


	public void setLoginDao(LoginDao loginDao) {
		this.loginDao = loginDao;
	}


	public LoginDao getLoginDao() {
		return loginDao;
	}


	public void setLeaseDao(LeaseDao leaseDao) {
		this.leaseDao = leaseDao;
	}
	
			
		public PaginationSupport searchAllLeaseByPage(int start) {
				
				return leaseDao.getLeaseByPage(null,null,null,start,PublicFinalData.ROLE_PAGE_MAX_SIZE);
			}
		
		
		public void loadMoneyAdd(int loadMoneys) {
			
			LoadMoneyMod loadMoney=new LoadMoneyMod();
			loadMoney.setLoadMoney(loadMoneys);
			 leaseDao.saveLoadMoney(loadMoney);
		}


		public LoadMoneyMod selectLoadMoneyById(int moneyId) {
			
			return leaseDao.selectLoadMoneyById(moneyId);
		}


		public void updateLoadMoney(int moneyId, int loadMoney) {
			
			LoadMoneyMod load=leaseDao.selectLoadMoneyById(moneyId);
			load.setLoadMoney(loadMoney);
			leaseDao.updateLoadMoney(load);
		}


		public void deleteLoadMoney(int[] moneyId) {

			List<LoadMoneyMod> loadList = new ArrayList<LoadMoneyMod>();
			for (int i = 0; i<moneyId.length; i++) {
				LoadMoneyMod load = leaseDao.selectLoadMoneyById(moneyId[i]);
				loadList.add(load);
			}
			 leaseDao.deleteLoadMoney(loadList);
			
		}


		public List<LeaseMod> selectLeaseForTen() {
			
		//	LeaseMod
			PaginationSupport ps=leaseDao.getLeaseByPage( null, "leaTime", null, 0, 9);
		
			List<LeaseMod> leaseList=ps.getItems();
			return leaseList;
		}
		
		
		
		
		
		
}
